/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 19
 * Time: 17:27
 */
class Solution4 {
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        int[] num = new int[nums1.length];
        int k = 0;
        int flag = -1;
        for (int i = 0; i < nums1.length; i++) {
            for (int j = 0; j < nums2.length; j++) {
                if(nums1[i] == nums2[j]) {
                    while(j < nums2.length) {
                        if(nums2[j] > nums1[i]) {
                            num[k++] = nums2[j];
                            flag = nums2[j];
                            break;
                        }
                        j++;
                    }
                }
            }
            if(flag == -1) {
                num[k++] = -1;
            }
            flag = -1;
        }
        return num;
    }
}
